home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / MacApp Release 10 / MacApp Release 10 - HD Ready / Libraries / Views / Sources / UODPartViewCommands.cp < prev    next >
Encoding:
Text File  |  1996-04-03  |  7.6 KB  |  212 lines  |  [TEXT/CWIE]

  1. //----------------------------------------------------------------------------------------
  2. // UODPartViewCommands.cp
  3. // Copyright © 1994-96 by Apple Computer, Inc. All rights reserved.
  4. //----------------------------------------------------------------------------------------
  5.  
  6. #if qContainer
  7.  
  8. #ifndef __UODPARTVIEWCOMMANDS__
  9. #include "UODPartViewCommands.h"
  10. #endif
  11.  
  12. #ifndef __UODPARTVIEW__
  13. #include "UODPartView.h"
  14. #endif
  15.  
  16.  
  17. //========================================================================================
  18. // CLASS TCopyODPartCommand
  19. //========================================================================================
  20. #undef Inherited
  21. #define Inherited TCommand
  22.  
  23. #pragma segment MASelCommand
  24. MA_DEFINE_CLASS_M1(TCopyODPartCommand, Inherited);
  25.  
  26. //----------------------------------------------------------------------------------------
  27. // TCopyODPartCommand::TCopyODPartCommand
  28. //----------------------------------------------------------------------------------------
  29. #pragma segment MASelCommand
  30.  
  31. TCopyODPartCommand::TCopyODPartCommand()
  32. {
  33.  
  34. } // TCopyODPartCommand::TCopyODPartCommand
  35.  
  36. //----------------------------------------------------------------------------------------
  37. // TCopyODPartCommand::ICopyODPartCommand
  38. //----------------------------------------------------------------------------------------
  39. #pragma segment MASelCommand
  40.  
  41. void TCopyODPartCommand::ICopyODPartCommand(CommandNumber itsCommandNumber,
  42.                                             TDocument*        itsDocument,
  43.                                             TODPartView*    thePartView)
  44. {
  45.     fDocument = itsDocument;    
  46.     fODPartView = thePartView;
  47.     this->ICommand(itsCommandNumber, NULL, kCantUndo, kDoesNotCauseChange, NULL);
  48. } // TCopyODPartCommand::ICopyODPartCommand
  49.  
  50. //----------------------------------------------------------------------------------------
  51. // TCopyODPartCommand::~TCopyODPartCommand
  52. //----------------------------------------------------------------------------------------
  53. #pragma segment MASelCommand
  54.  
  55.  
  56. TCopyODPartCommand::~TCopyODPartCommand()
  57. {
  58. } // TCopyODPartCommand::~TCopyODPartCommand
  59.  
  60. //----------------------------------------------------------------------------------------
  61. // TCopyODPartCommand::DoIt
  62. //----------------------------------------------------------------------------------------
  63. #pragma segment MASelCommand
  64.  
  65.  
  66. void TCopyODPartCommand::DoIt()
  67. {
  68.     CADocumentRef    theClipboardDocument = CAGetClipboardDocument();
  69.     CADocumentRef    sourceDocument     = fDocument->GetContainer();
  70.     CAFrameRef         sourceFrameRef     = fODPartView->GetFrameRef();
  71.     CACloneKey        cloneKey          = CABeginClone(sourceDocument, theClipboardDocument, kCACloneCopy);
  72.     CAFrameRef        clipFrameRef    = CACloneFrameRef(sourceFrameRef,sourceDocument,
  73.                                                             theClipboardDocument,TRUE,cloneKey);
  74.     CAEndClone(sourceDocument,theClipboardDocument,cloneKey);
  75. } // TCopyODPartCommand::DoIt
  76.  
  77.  
  78.  
  79. //========================================================================================
  80. // CLASS TCutODPartCommand
  81. //========================================================================================
  82. #undef Inherited
  83. #define Inherited TCommand
  84.  
  85. #pragma segment MASelCommand
  86. MA_DEFINE_CLASS_M1(TCutODPartCommand, Inherited);
  87.  
  88. //----------------------------------------------------------------------------------------
  89. // TCutODPartCommand::TCutODPartCommand
  90. //----------------------------------------------------------------------------------------
  91. #pragma segment MASelCommand
  92.  
  93. TCutODPartCommand::TCutODPartCommand()
  94. {
  95.  
  96. } // TCutODPartCommand::TCutODPartCommand
  97.  
  98. //----------------------------------------------------------------------------------------
  99. // TCutODPartCommand::ICutODPartCommand
  100. //----------------------------------------------------------------------------------------
  101. #pragma segment MASelCommand
  102.  
  103. void TCutODPartCommand::ICutODPartCommand(CommandNumber itsCommandNumber,
  104.                                         TDocument*        itsDocument,
  105.                                         TODPartView*    thePartView)
  106. {
  107.     fDocument = itsDocument;    
  108.     fODPartView = thePartView;
  109.     this->ICommand(itsCommandNumber, NULL, kCantUndo, kCausesChange, NULL);
  110. } // TCutODPartCommand::ICutODPartCommand
  111.  
  112. //----------------------------------------------------------------------------------------
  113. // TCutODPartCommand::~TCutODPartCommand
  114. //----------------------------------------------------------------------------------------
  115. #pragma segment MASelCommand
  116.  
  117. TCutODPartCommand::~TCutODPartCommand()
  118. {
  119. } // TCutODPartCommand::~TCutODPartCommand
  120.  
  121. //----------------------------------------------------------------------------------------
  122. // TCutODPartCommand::DoIt
  123. //----------------------------------------------------------------------------------------
  124. #pragma segment MASelCommand
  125.  
  126. void TCutODPartCommand::DoIt()
  127. {
  128.     CADocumentRef    theClipDocument = CAGetClipboardDocument();
  129.     CADocumentRef    sDocument     = fDocument->GetContainer();
  130.     CAFrameRef         sFrameRef     = fODPartView->GetFrameRef();
  131.     CACloneKey        cKey          = CABeginClone(sDocument, theClipDocument, kCACloneCut);
  132.     CAFrameRef        cRef        = CACloneFrameRef(sFrameRef,sDocument,
  133.                                                         theClipDocument,TRUE,cKey);
  134.     CAEndClone(sDocument,theClipDocument,cKey);
  135.     fODPartView->RemovePart(); //not condusive to an undo! (Save it off, remove it in committ)
  136. } // TCutODPartCommand::DoIt
  137.  
  138.  
  139. //========================================================================================
  140. // CLASS TPasteODPartCommand
  141. //========================================================================================
  142. #undef Inherited
  143. #define Inherited TCommand
  144.  
  145. #pragma segment MASelCommand
  146. MA_DEFINE_CLASS_M1(TPasteODPartCommand, Inherited);
  147.  
  148. //----------------------------------------------------------------------------------------
  149. // TPasteODPartCommand::TPasteODPartCommand
  150. //----------------------------------------------------------------------------------------
  151. #pragma segment MASelCommand
  152.  
  153. TPasteODPartCommand::TPasteODPartCommand()
  154. {
  155.  
  156. } // TPasteODPartCommand::TPasteODPartCommand
  157.  
  158. //----------------------------------------------------------------------------------------
  159. // TPasteODPartCommand::IPasteODPartCommand
  160. //----------------------------------------------------------------------------------------
  161. #pragma segment MASelCommand
  162.  
  163. void TPasteODPartCommand::IPasteODPartCommand(CommandNumber itsCommandNumber,
  164.                                                 TDocument*        itsDocument,
  165.                                                 TODPartView*    thePartView)
  166. {
  167.     fDocument = itsDocument;    
  168.     fODPartView = thePartView;
  169.     this->ICommand(itsCommandNumber, NULL, kCantUndo, kCausesChange, NULL);
  170. } // TPasteODPartCommand::IPasteODPartCommand
  171.  
  172. //----------------------------------------------------------------------------------------
  173. // TPasteODPartCommand::~TPasteODPartCommand
  174. //----------------------------------------------------------------------------------------
  175. #pragma segment MASelCommand
  176.  
  177. TPasteODPartCommand::~TPasteODPartCommand()
  178. {
  179. } // TPasteODPartCommand::~TPasteODPartCommand
  180.  
  181. //----------------------------------------------------------------------------------------
  182. // TPasteODPartCommand::DoIt
  183. //----------------------------------------------------------------------------------------
  184. #pragma segment MASelCommand
  185.  
  186. void TPasteODPartCommand::DoIt()
  187. {
  188.     if(fODPartView->ContainsClipType(kCAScrapTypeODBentoContainer))
  189.     {
  190.         CADocumentRef    theClipboardDocument;
  191.         long            scrapLength;
  192.         long            scrapOffset;
  193.         Handle            scrapHandle;
  194.  
  195.         //If we have a part, get rid of it
  196.         if(fODPartView->HasPart())
  197.             fODPartView->RemovePart();
  198.             
  199.         // Get the container stream
  200.         scrapHandle = NewHandle(0);
  201.         //Lock handle?    FailOSErr!
  202.         scrapLength = GetScrap(scrapHandle, kCAScrapTypeODBentoContainer, &scrapOffset );
  203.  
  204.         // Open the container
  205.         theClipboardDocument = CAOpenDocument (NULL, scrapHandle, 0, scrapLength);
  206.         fODPartView->AquirePartFromDocument(theClipboardDocument);
  207.         CACloseDocument(theClipboardDocument);
  208.         DisposeHandle(scrapHandle);
  209.     }
  210. } // TPasteODPartCommand::DoIt
  211.  
  212. #endif //qContainer